package person.learn.filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * Created by barton on 16-1-29.
 * 1.过滤器,过滤的是资源而不是请求
 * 2.结合WebConfig里重写的appFilter进行测试。appFilter()方法可以追加path等
 */
@Component
public class ResourcesFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter初始化,在容器启动时运行");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        System.out.println("执行filter,对请求做额外操作");

        // 继续执行下一个filter
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        System.out.println("Filter销毁,容器停止时运行");
    }
}
